﻿public class DupAstTree : LuaAstTree
{
    public LuaAstTree Target;
    private bool _inited;
    private string _varName;
    private int _index;
    public DupAstTree(int i, LuaAstTree target)
    {
        _index = i;
        Target = target;
        _inited = false;
    }
    public override void WriteTo(ICodeWriter writer)
    {
        if (_inited)
        {
            writer.Code(_varName);
        }
        else
        {
            _inited = true;
            _varName = $"__var{_index}__";
            writer.Code($"local {_varName} = ");
            Target.WriteTo(writer);
        }
    }
}

